//=============================================================================
// Helper functions
//  Dealing with files and power-of-two
//
// 
//
// Bodhi Crandall-Rus (boder.us)
// Sept 10, 2006
//=============================================================================

#ifndef HELPER_CPP
#define HELPER_CPP

#include "common.hpp"
#include <fstream>

namespace KEG
{
	inline size_t NextPow2(size_t n)
	{
		n -= 1;
		n |= n >> 1;
		n |= n >> 2;
		n |= n >> 4;
		n |= n >> 8;
		n |= n >> 16;
#ifdef _WIN64
		n |= n >> 32;
#endif
		n += 1;

		return n;
	}

	inline bool IsPow2(size_t n)
	{
		return !(n - NextPow2(n));
	}

	// File/String Conversion Functions
	std::string FilenameToString( const std::string& filename );

	std::string FileToString( std::ifstream& fin );

	void FilenameToStringstream( std::istringstream& strstr, const std::string& filename );

	void FileToStringstream( std::istringstream& strstr, std::ifstream& fin );
}

#endif


